package changceilingcolor003;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import com.sun.org.apache.xpath.internal.operations.Bool;

import toxi.geom.Vec3D;

//check out comment
public abstract class Actors {

	HashMap<String, Double>  DesireList = new HashMap<String, Double> ();
	HashMap<String, Double>  SelfAttrationList = new HashMap<String, Double> ();
	String[] properties = { "ArtScent", "Type1Scent","Type2Scent","Type3Scent", "GoTheInitialDestinationScent"};
	ChangCeilingColor003 p5;
	public boolean m_active = true;
	abstract double GetIntrestDuration();
	void SetIntrestDuration(double _InterestDuration)
	{
		InterestDuration = _InterestDuration;
	}
	double InterestDuration = 0;

	
	Actors(ChangCeilingColor003 parent,Vec3D _location)
	{
		p5 = parent;
		//set all the initial value to zero        
		for(int i=0;i < properties.length; i++)
		{
			DesireList.put(properties[i], 0.0);        
			SelfAttrationList.put(properties[i], 0.0);//Type 1 has no artistic value          
		}
		location = _location;
	}
	Vec3D LocationDelta = new Vec3D(0, 0, 0);
	

	void  SetLoctation(Vec3D v)
	{
		location = v;
		OnChangeLocationEvent();
	}
	
	void SetDeltaX(float x)
	{
		LocationDelta.x = x;
		OnChangeLocationEvent();
	}
	
	void SetDeltaY(float y)
	{
		LocationDelta.y = y;
		OnChangeLocationEvent();
	}
	
	void SetDeltaZ(float z)
	{
		LocationDelta.z = z;
		OnChangeLocationEvent();
	}
	
	
	void SetX(float x)
	{
		location.x = x;
		OnChangeLocationEvent();
	}
	
	void SetY(float y)
	{
		location.y = y;
		OnChangeLocationEvent();
	}
	
	void SetZ(float z)
	{
		location.z = z;
		OnChangeLocationEvent();
	}
	
	//void SetAttractionRadious(double newAttractionRadios)
	//{
		//AttractionRadious = newAttractionRadios;
	//}
	void OnChangeLocationEvent()
	{
		
	}

	double GetAtrctivnessGrade(Actors otherActor)
	{
		Iterator<Entry<String, Double>> i = DesireList.entrySet().iterator();  // Get an iterator

		double grade= 0.0f;

		float distance = otherActor.location.distanceTo(location);
		if(otherActor == this || otherActor == null || !otherActor.m_active )	            
		{
			return 0;
		}

		while (i.hasNext()) 
		{
			Map.Entry<String, Double> me = (Map.Entry<String, Double>)i.next();
			Object obj =otherActor.SelfAttrationList.get(me.getKey());
			if( (obj != null) && (otherActor.location != null))
			{     
				grade = grade + ( (Double)otherActor.SelfAttrationList.get(me.getKey()) ) *( (Double) me.getValue());
			}
			else 
			{
				return 0.0f;
			}	         
		}
		grade =  grade /distance;
		return grade;
	}
	private Vec3D location; 
	public Vec3D GetLocation()
	{
		return location.add(LocationDelta);
	}
	public void SetLocation(Vec3D v)
	{
		location =v;
	}
	
	protected double AttractionRadious = 0.01;
	public abstract double GetAttractionRadious();
	public void SetAttractionRadious(double newAttractionRadios)
	{
		AttractionRadious = newAttractionRadios;
	}

	public abstract void update(World w);
	public abstract void Draw(); 

}
